{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Determine if String Halves Are Alike"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string #counting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串 #计数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: halvesAreAlike"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #判断字符串的两半是否相似"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个偶数长度的字符串 <code>s</code> 。将其拆分成长度相同的两半，前一半为 <code>a</code> ，后一半为 <code>b</code> 。</p>\n",
    "\n",
    "<p>两个字符串 <strong>相似</strong> 的前提是它们都含有相同数目的元音（<code>'a'</code>，<code>'e'</code>，<code>'i'</code>，<code>'o'</code>，<code>'u'</code>，<code>'A'</code>，<code>'E'</code>，<code>'I'</code>，<code>'O'</code>，<code>'U'</code>）。注意，<code>s</code> 可能同时含有大写和小写字母。</p>\n",
    "\n",
    "<p>如果<em> </em><code>a</code><em> </em>和<em> </em><code>b</code> 相似，返回 <code>true</code> ；否则，返回 <code>false</code> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"book\"\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>a = \"b<strong>o</strong>\" 且 b = \"<strong>o</strong>k\" 。a 中有 1 个元音，b 也有 1 个元音。所以，a 和 b 相似。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"textbook\"\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>a = \"t<strong>e</strong>xt\" 且 b = \"b<strong>oo</strong>k\" 。a 中有 1 个元音，b 中有 2 个元音。因此，a 和 b 不相似。\n",
    "注意，元音 o 在 b 中出现两次，记为 2 个。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>2 &lt;= s.length &lt;= 1000</code></li>\n",
    "\t<li><code>s.length</code> 是偶数</li>\n",
    "\t<li><code>s</code> 由 <strong>大写和小写</strong> 字母组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [determine-if-string-halves-are-alike](https://leetcode.cn/problems/determine-if-string-halves-are-alike/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [determine-if-string-halves-are-alike](https://leetcode.cn/problems/determine-if-string-halves-are-alike/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"book\"', '\"textbook\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        s = s.lower()\n",
    "        index = int(len(s)/2)\n",
    "        a = s[0:index]\n",
    "        b = s[index:]\n",
    "        num1,num2 = 0,0\n",
    "        testlist = ['a','e','i','o','u']\n",
    "        for i in list(a):\n",
    "            if i in testlist:\n",
    "                num1 += 1\n",
    "        for j in list(b):\n",
    "            if j in testlist:\n",
    "                num2 += 1\n",
    "        if num1 == num2:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        return sum(i in ('aeiouAEIOU') for i in s[:len(s)//2]) == sum(j in ('aeiouAEIOU')  for j in s[len(s)//2:])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        VOWELS = \"aeiouAEIOU\"\n",
    "        a , b = s[:len(s) // 2] , s[len(s) // 2:]\n",
    "        return sum(c in VOWELS for c in a) == sum(c in VOWELS for c in b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        return sum(i in set('aeiouAEIOU') for i in s[:len(s)//2]) == sum(j in set('aeiouAEIOU')  for j in s[len(s)//2:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        vowel = \"aeiouAEIOU\"\n",
    "        n = len(s) // 2\n",
    "        a, b = 0, 0\n",
    "        for i in range(n):\n",
    "            if s[i] in vowel:\n",
    "                a += 1\n",
    "            if s[2 * n - 1 - i] in vowel:\n",
    "                b += 1\n",
    "        return a == b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        cnt, n = 0, len(s) >> 1\n",
    "        vowels = set('aeiouAEIOU')\n",
    "        for i in range(n):\n",
    "            cnt += s[i] in vowels\n",
    "            cnt -= s[i + n] in vowels\n",
    "        return cnt == 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        aeiou = 'aeiou'\n",
    "        s = s.lower()\n",
    "        ans = 0\n",
    "        for i in range(len(s)//2):\n",
    "            if s[i] in aeiou and s[-(i + 1)] not in aeiou:\n",
    "                ans += 1\n",
    "            elif s[i] not in aeiou and s[-(i + 1)] in aeiou:\n",
    "                ans -= 1\n",
    "        \n",
    "        if ans == 0:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        tar = ['a','e','i','o','u','A','E','I','O','U']\n",
    "        n = len(s)\n",
    "        count1,count2 = 0,0\n",
    "        for i in tar:\n",
    "            count1 += s[:len(s)//2].count(i)\n",
    "            count2 += s[len(s)//2:].count(i)\n",
    "        if count1 == count2:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        z=['a','e','i','o','u']\n",
    "        t=s.lower()\n",
    "        return sum(i in z for i in t[:len(t)//2])==sum(i in z for i in t[len(t)//2:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        index = int(len(s)/2)\n",
    "        firsthalf = list(s.lower())[:index]\n",
    "        secondhalf = list(s.lower())[index:]\n",
    "        firstsum,secondsum =0,0\n",
    "        temp =['a','e','i','o','u']\n",
    "        for v in temp:\n",
    "            firstsum = firstsum+ firsthalf.count(v)\n",
    "            secondsum = secondsum+ secondhalf.count(v)\n",
    "        if firstsum == secondsum: return True\n",
    "        else: return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def halvesAreAlike(self, s: str) -> bool:\r\n",
    "        def numyuanyin(s1:str):\r\n",
    "            yuanyin = set('aeiouAEIOU')\r\n",
    "            return sum(int(ch in yuanyin) for ch in s1)\r\n",
    "        nn = len(s)//2\r\n",
    "        return numyuanyin(s[:nn]) == numyuanyin(s[nn:])\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        c_st = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}\n",
    "        cnt = 0\n",
    "        len_s = len(s)\n",
    "        for i in range(len_s // 2):\n",
    "            if s[i] in c_st:\n",
    "                cnt += 1\n",
    "            if s[len_s - 1 - i] in c_st:\n",
    "                cnt -= 1\n",
    "\n",
    "        return cnt == 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        VOWELS = \"aeiouAEIOU\"\n",
    "        a, b = s[: len(s) // 2], s[len(s) // 2 :]\n",
    "        return sum(c in VOWELS for c in a) == sum(c in VOWELS for c in b)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        set  = {\"a\",\"e\",\"i\",\"o\",\"u\",\"A\",\"E\",\"I\",\"O\",\"U\"}\n",
    "        count1 = 0\n",
    "        count2 = 0\n",
    "        for i in range(len(s)//2):\n",
    "            if s[i] in set:\n",
    "                count1 += 1\n",
    "        for j in range(len(s)//2,len(s)):\n",
    "            if s[j] in set:\n",
    "                count2 += 1\n",
    "        return count1 == count2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        vols = set('aeiouAEIOU')\n",
    "        \n",
    "        cnt = 0\n",
    "        for c in s[:len(s)//2]:\n",
    "            if c in vols:\n",
    "                cnt += 1\n",
    "        for c in s[len(s)//2:]:\n",
    "            if c in vols:\n",
    "                cnt -= 1\n",
    "        \n",
    "        return cnt == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        aeiou = 'aeiouAEIOU'\n",
    "        s1 = 0\n",
    "        s2 = 0\n",
    "        for i in range(int(len(s)/2)):\n",
    "            if s[i] in aeiou:\n",
    "                s1 += 1\n",
    "            if s[-i-1] in aeiou:\n",
    "                s2 += 1\n",
    "        return s1 == s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        li = ['a','e','i','o','u','A','E','I','O','U']\n",
    "        num = 0\n",
    "        for i in range(len(s) // 2):\n",
    "            if s[i] in li:\n",
    "                num += 1\n",
    "            if s[len(s) - 1 - i] in li:\n",
    "                num -= 1\n",
    "        return not num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        half = n // 2\n",
    "        a = s[0: half].lower()\n",
    "        b = s[half:].lower()\n",
    "        suma = sum([1 for it in a if it in \"aeiou\"])\n",
    "        sumb = sum([1 for it in b if it in \"aeiou\"])\n",
    "        return suma == sumb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        s1 = s[:len(s)//2]\n",
    "        s2 = s[len(s)//2:]\n",
    "        print(s1)\n",
    "        print(s2)\n",
    "        sum1 = sum2 = 0\n",
    "        for i in s1:\n",
    "            if i in ('aeiouAEIOU'):\n",
    "                sum1 += 1\n",
    "        for j in s2:\n",
    "            if j in ('aeiouAEIOU'):\n",
    "                sum2 += 1\n",
    "        return sum1 == sum2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        z=['a','e','i','o','u']\n",
    "        t=s.lower()\n",
    "        n=len(t)//2\n",
    "        x=collections.Counter(t[:n])\n",
    "        y=collections.Counter(t[n:])\n",
    "        a=0\n",
    "        b=0\n",
    "        for i in x:\n",
    "            if i in z:\n",
    "                a+=x[i]\n",
    "        for i in y:\n",
    "            if i in z:\n",
    "                b+=y[i]\n",
    "        return a==b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        ss = s.lower()\n",
    "        s1 = ss[:int(len(s)/2)]\n",
    "        s2 = ss[int(len(s)/2):]\n",
    "        n = 0\n",
    "        m = 0\n",
    "        for i in s1:\n",
    "            if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u':\n",
    "                n += 1\n",
    "        \n",
    "        for i in s2:\n",
    "            if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u':\n",
    "                m += 1\n",
    "               \n",
    "        return n == m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        n=len(s)\n",
    "        a=s[:n//2]\n",
    "        b=s[n//2:]\n",
    "        ans1=0\n",
    "        ans2=0\n",
    "        for i in a:\n",
    "            if i in ['a','e','i','o','u','A','E','I','O','U']:\n",
    "                ans1+=1\n",
    "        for j in b:\n",
    "            if j in ['a','e','i','o','u','A','E','I','O','U']:\n",
    "                ans2+=1\n",
    "        return ans1==ans2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        set  = {\"a\",\"e\",\"i\",\"o\",\"u\",\"A\",\"E\",\"I\",\"O\",\"U\"}\n",
    "        count1 = 0\n",
    "        count2 = 0\n",
    "        for i in range(len(s)//2):\n",
    "            if s[i] in set:\n",
    "                count1 += 1\n",
    "        for j in range(len(s)//2,len(s)):\n",
    "            if s[j] in set:\n",
    "                count2 += 1\n",
    "        return count1 == count2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        s = s.lower()\n",
    "        index = int(len(s)/2)\n",
    "        a = s[0:index]\n",
    "        b = s[index:]\n",
    "        num1,num2 = 0,0\n",
    "        testlist = ['a','e','i','o','u']\n",
    "        for i in list(a):\n",
    "            if i in testlist:\n",
    "                num1 += 1\n",
    "        for j in list(b):\n",
    "            if j in testlist:\n",
    "                num2 += 1\n",
    "        if num1 == num2:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        cnt = 0\n",
    "        ss = set('aeiouAEIOU')\n",
    "        for idx, c in enumerate(s):\n",
    "            if c not in ss:\n",
    "                continue\n",
    "            cnt += 1 if idx < len(s) / 2 else -1\n",
    "        return cnt == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        ss = s.lower()\n",
    "        s1 = ss[:int(len(s)/2)]\n",
    "        s2 = ss[int(len(s)/2):]\n",
    "        n = 0\n",
    "        m = 0\n",
    "        for i in s1:\n",
    "            if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u':\n",
    "                n += 1\n",
    "        \n",
    "        for i in s2:\n",
    "            if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u':\n",
    "                m += 1\n",
    "               \n",
    "        return n == m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        lth = len(s)//2\n",
    "        s1 = s[:lth]\n",
    "        s2 = s[lth:]\n",
    "        lst = ['a','e','i','o','u','A','E','I','O','U']\n",
    "        l1 = l2 = 0\n",
    "        for i in range(lth):\n",
    "            if s1[i] in lst:\n",
    "                l1 += 1\n",
    "            if s2[i] in lst:\n",
    "                l2 += 1\n",
    "        return True if l1==l2 else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        yuanyin = ['a','e','i','o','u','A','E','I','O','U']\n",
    "        s1 = s[:n//2]\n",
    "        s2 = s[n//2:]\n",
    "        return sum([1 for i in s[:n//2] if i in yuanyin])==sum([1 for i in s[n//2:] if i in yuanyin])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        s=s.lower()\n",
    "        n=len(s)//2\n",
    "        c1=sum(c for i,c in Counter(s[:n]).items() if i in 'aeiou')\n",
    "        c2=sum(c for i,c in Counter(s[n:]).items() if i in 'aeiou')\n",
    "        return c1==c2\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        yuan = {'a','e','i','o','u','A','E','I','O','U'}\n",
    "        s = s.lower()\n",
    "        count1 = 0\n",
    "        count2 = 0\n",
    "        for i in range(len(s)//2):\n",
    "            if s[i] in yuan:\n",
    "                count1 = count1+1\n",
    "            if s[-i-1] in yuan:\n",
    "                count2 = count2+1\n",
    "        return count1==count2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        VOWELS = \"aeiouAEIOU\"\n",
    "        a,b = s[:len(s)//2],s[len(s)//2:]\n",
    "        return sum(c in VOWELS for c in a) == sum(c in VOWELS for c in b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        st='aeiouAEIOU'\n",
    "        n=len(s)\n",
    "        s1=s[:n//2]\n",
    "        s2=s[n//2:]\n",
    "        cur1,cur2=0,0\n",
    "        for word in s1:\n",
    "            if word in st:\n",
    "                cur1+=1\n",
    "        for word in s2:\n",
    "            if word in st:\n",
    "                cur2+=1\n",
    "        return cur1==cur2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        y={'a','e','i','o','u','A','E','I','O','U'}\n",
    "        s1,s2=s[:len(s)//2],s[len(s)//2:]\n",
    "        rs1=[x for x in s1 if x in y]\n",
    "        rs2=[x for x in s2 if x in y]\n",
    "        #print(rs1,rs2)\n",
    "        if len(rs1)==len(rs2) :\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "t_chr=['a','e','i','o','u','A','E','I','O','U']\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        a,b=0,0\n",
    "        for i in range(len(s)//2):\n",
    "            if s[i] in t_chr:\n",
    "                a+=1\n",
    "            if s[-i-1] in t_chr:\n",
    "                b+=1\n",
    "        return a==b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        mid=len(s)//2\n",
    "        a=s[:mid]\n",
    "        b=s[mid:]\n",
    "        sum_a=0\n",
    "        sum_b=0\n",
    "        target=['a','e','i','o','u','A','E','I','O','U']\n",
    "        for i in a:\n",
    "            if i in target:\n",
    "                sum_a=sum_a+1\n",
    "        for i in b:\n",
    "            if i in target:\n",
    "                sum_b=sum_b+1\n",
    "        if (sum_a==sum_b):\n",
    "            return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        y={'a','e','i','o','u','A','E','I','O','U'}        \n",
    "        rs1=[x for x in s[:len(s)//2] if x in y]\n",
    "        rs2=[x for x in s[len(s)//2:] if x in y]\n",
    "        #print(rs1,rs2)\n",
    "        if len(rs1)==len(rs2) :\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        cnt = 0\n",
    "        ss = set('aeiouAEIOU')\n",
    "        for idx, c in enumerate(s):\n",
    "            if c not in ss:\n",
    "                continue\n",
    "            cnt += 1 if idx < len(s) / 2 else -1\n",
    "        return cnt == 0\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        tag = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}\n",
    "        mid_index = len(s) // 2\n",
    "        c1 = c2 = 0\n",
    "        for i in range(0, mid_index):\n",
    "            if s[i] in tag:\n",
    "                c1 += 1\n",
    "        for i in range(mid_index, len(s)):\n",
    "            if s[i] in tag:\n",
    "                c2 += 1\n",
    "        return c1 == c2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        s = s.lower()\n",
    "        l, r = s[:len(s)//2], s[len(s)//2:]\n",
    "        cl = Counter(l)\n",
    "        cr = Counter(r)\n",
    "        return sum(cl[x] for x in 'aeiou') == sum(cr[x] for x in 'aeiou')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def helper(s: str) -> int:\n",
    "    return sum([s.count(_) for _ in 'aeiou'])\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        a, b = s.lower()[:int(len(s)/2)], s.lower()[int(len(s)/2):]\n",
    "        return helper(a) == helper(b)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        vowels = 'aeiouAEIOU'\n",
    "        l,r = s[:len(s)//2],s[len(s)//2:]\n",
    "        return sum(char in vowels for char in l) == sum(char in vowels for char in r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        l=['a','e','i','o','u','A','E','I','O','U']\n",
    "        n=0\n",
    "        m=0\n",
    "        for i in s[0:len(s)//2]:\n",
    "            if i in l:\n",
    "                n+=1\n",
    "        for i in s[len(s)//2:]:\n",
    "            if i in l:\n",
    "                m+=1\n",
    "        return n==m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        vowel_set = set(['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'])\n",
    "        n = len(s)\n",
    "        first_half = s[:n // 2]\n",
    "        last_half = s[n // 2:]\n",
    "        first = second = 0\n",
    "        for s in first_half:\n",
    "            if s in vowel_set:\n",
    "                first += 1\n",
    "        for s in last_half:\n",
    "            if s in vowel_set:\n",
    "                second += 1\n",
    "        return first == second"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        n=len(s)\n",
    "        l,r=0,0\n",
    "        for i in s[:n//2]:\n",
    "            if i in ['a','e','i','o','u','A','E','I','O','U']:\n",
    "                l+=1\n",
    "        for i in s[n//2:]:\n",
    "            if i in ['a','e','i','o','u','A','E','I','O','U']:\n",
    "                r+=1\n",
    "        return l==r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        count = 0\n",
    "        l = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']\n",
    "        s1, s2 = s[0:len(s)//2], s[len(s)//2:len(s)]\n",
    "        for i in s1:\n",
    "            if i in l:\n",
    "                count += 1\n",
    "        for i in s2:\n",
    "            if i in l:\n",
    "                count -= 1\n",
    "        if not count:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        ref = ('a','e','i','o','u','A','E','I','O','U')\n",
    "        n = len(s)//2\n",
    "        s1 = s[:n]\n",
    "        s2 = s[n:]\n",
    "        return func1(s1,ref) == func1(s2,ref)\n",
    "\n",
    "def func1(s,ref):\n",
    "    cnt = 0\n",
    "    for v in s:\n",
    "        if v in ref:\n",
    "            cnt += 1\n",
    "    return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def helper(s: str) -> int:\n",
    "    return sum([s.lower().count(_) for _ in 'aeiou'])\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        # a, b = s.lower()[:int(len(s)/2)], s.lower()[int(len(s)/2):]\n",
    "        return helper(s[:int(len(s)/2)]) == helper(s[int(len(s)/2):])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        VOWELS = \"aeiouAEIOU\"\n",
    "        a, b = s[:len(s) // 2], s[len(s) // 2:]\n",
    "        return sum(c in VOWELS for c in a) == sum(c in VOWELS for c in b)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "         vowels = \"aeiouAEIOU\"\n",
    "         str1 , str2 = s[ : len(s)//2] , s[len(s)//2 : ]\n",
    "         return sum(ch in vowels for ch in str1) == sum(ch in vowels for ch in str2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        ref = ('a','e','i','o','u','A','E','I','O','U')\n",
    "        n = len(s)//2\n",
    "        return func1(s[:n],ref) == func1(s[n:],ref)\n",
    "\n",
    "def func1(s,ref):\n",
    "    cnt = 0\n",
    "    for v in s:\n",
    "        if v in ref:\n",
    "            cnt += 1\n",
    "    return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        sa, sb = 0, 0\n",
    "        s = s.lower()\n",
    "        for i in range(len(s)//2):\n",
    "            if s[i] in ['a', 'e', 'i', 'o', 'u']:\n",
    "                sa += 1\n",
    "        for j in range(len(s)//2, len(s)):\n",
    "            if s[j] in ['a', 'e', 'i', 'o', 'u']:\n",
    "                sb += 1\n",
    "        if sa == sb:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        n = len(s)//2\n",
    "        jh = set(\"aeiouAEIOU\")\n",
    "        x = 0\n",
    "        for i in range(n):\n",
    "            x += s[i] in jh\n",
    "            x -= s[i+n] in jh\n",
    "        return x == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        first_half=s[:int(len(s)//2)]\n",
    "        second_half=s[int(len(s)//2):]\n",
    "        print(first_half, second_half)\n",
    "        halves_set=('a','e','i','o','u','A','E','I','O','U')\n",
    "        number_of_halves_first_half=[item for item in first_half if item in halves_set]\n",
    "        number_of_halves_second_half=[item for item in second_half if item in halves_set]\n",
    "        if len(number_of_halves_first_half)==len(number_of_halves_second_half):\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        MAPPING = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']\n",
    "        n = len(s)\n",
    "        a = 0\n",
    "        b = 0\n",
    "        for i in range(n // 2):\n",
    "            if s[i] in MAPPING:\n",
    "                a += 1\n",
    "            if s[i + n // 2] in MAPPING:\n",
    "                b += 1\n",
    "        return a == b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        def count_vowels(s: str) -> int:\n",
    "            _list = ['a', 'e', 'i', 'o', 'u']\n",
    "            count = 0\n",
    "            for x in s:\n",
    "                if x in _list:\n",
    "                    count += 1\n",
    "            return count\n",
    "        \n",
    "        _size = len(s)\n",
    "        _string = s.lower()\n",
    "        s1 = _string[:_size // 2]\n",
    "        s2 = _string[_size // 2:]\n",
    "        if count_vowels(s1) == count_vowels(s2):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        n=len(s)\n",
    "        a=s[:n//2]\n",
    "        b=s[n//2:]\n",
    "        ans1=0\n",
    "        ans2=0\n",
    "        for i in a:\n",
    "            if i in ['a','e','i','o','u','A','E','I','O','U']:\n",
    "                ans1+=1\n",
    "        for j in b:\n",
    "            if j in ['a','e','i','o','u','A','E','I','O','U']:\n",
    "                ans2+=1\n",
    "        return ans1==ans2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def helper(s: str) -> int:\n",
    "    return sum([s.count(_) for _ in 'aeiou'])\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        a, b = s.lower()[:int(len(s)/2)], s.lower()[int(len(s)/2):]\n",
    "        return helper(a) == helper(b)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        a = s[: n//2]\n",
    "        b = s[n//2 :]\n",
    "        pattern = ['a','e','i','o','u']\n",
    "        cnt_a, cnt_b = 0, 0\n",
    "        for i in range(len(a)):\n",
    "            if a[i].lower() in pattern:\n",
    "                cnt_a += 1\n",
    "            if b[i].lower() in pattern:\n",
    "                cnt_b += 1\n",
    "        return cnt_a == cnt_b\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        return sum(i in set(\"aeiouAEIOU\") for i in s[:len(s) // 2]) == sum(j in set(\"aeiouAEIOU\") for j in s[len(s) // 2:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        n=len(s)//2\n",
    "        c1=c2=0\n",
    "        for i in range(n):\n",
    "            if s[i] in ['a','e','i','o','u','A','E','I','O','U']:\n",
    "                c1+=1\n",
    "        for i in range(n,n*2):\n",
    "            if s[i] in ['a','e','i','o','u','A','E','I','O','U']:\n",
    "                c2+=1\n",
    "        return c1==c2\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        yuan = ['a','e','i','o','u','A','E','I','O','U']\n",
    "        n = len(s)\n",
    "        a = s[0:n//2]\n",
    "        a_count = 0\n",
    "        b = s[n//2:]\n",
    "        b_count = 0\n",
    "        for i in range(0,n//2):\n",
    "            if a[i] in yuan:\n",
    "                a_count += 1\n",
    "            if b[i] in yuan:\n",
    "                b_count += 1\n",
    "        if a_count == b_count:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        yuanyin = ['a','e','i','o','u','A','E','I','O','U']\n",
    "        s1 = s[:n//2]\n",
    "        s2 = s[n//2:]\n",
    "        return sum([1 for i in s1 if i in yuanyin])==sum([1 for i in s2 if i in yuanyin])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        VOWELS = \"aeiouAEIOU\"\n",
    "        a, b = s[:len(s) // 2], s[len(s) // 2:]\n",
    "        return sum(c in VOWELS for c in a) == sum(c in VOWELS for c in b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        s = s.lower()\n",
    "        l, r = s[:len(s)//2], s[len(s)//2:]\n",
    "        cl = Counter(l)\n",
    "        cr = Counter(r)\n",
    "        return sum(cl[x] for x in 'aeiou') == sum(cr[x] for x in 'aeiou')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        n=len(s)\n",
    "        a=s[:n//2]\n",
    "        b=s[n//2:]\n",
    "        ans1=0\n",
    "        ans2=0\n",
    "        for i in a:\n",
    "            if i in ['a','e','i','o','u','A','E','I','O','U']:\n",
    "                ans1+=1\n",
    "        for j in b:\n",
    "            if j in ['a','e','i','o','u','A','E','I','O','U']:\n",
    "                ans2+=1\n",
    "        return ans1==ans2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        num = len(s)//2\n",
    "        def jishu(s):\n",
    "            list1 = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']\n",
    "            res = 0\n",
    "            for i in s:\n",
    "                if i in list1:\n",
    "                    res+=1\n",
    "            return res  \n",
    "        return jishu(s[:num])==jishu(s[num:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        s = s.lower()\n",
    "        yuanyin = \"aeiou\"\n",
    "        a = s[:int(len(s)/2)]\n",
    "        b = s[int(len(s)/2):]\n",
    "        a1 = 0\n",
    "        a2 = 0\n",
    "        for value in a:\n",
    "            if value in yuanyin:\n",
    "                a1 += 1\n",
    "        for value in b:\n",
    "            if value in yuanyin:\n",
    "                a2 += 1\n",
    "        return a1==a2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        abd={'a':0,'e':0,'i':0,'o':0,'u':0,'A':0,'E':0,'I':0,'O':0,'U':0}\n",
    "        leftcount,left=0,s[:len(s)//2]\n",
    "        for i in left:\n",
    "            if i in abd:\n",
    "                leftcount+=1\n",
    "        rightcount,right=0,s[len(s)//2:]\n",
    "        for i in right:\n",
    "            if i in abd:\n",
    "                rightcount+=1\n",
    "        return leftcount==rightcount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        def count_meta(subs):\n",
    "            cnt = 0\n",
    "            for c in subs:\n",
    "                if c in('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'):\n",
    "                    cnt += 1\n",
    "            return cnt\n",
    "\n",
    "        return count_meta(s[:len(s)//2]) == count_meta(s[len(s)//2:])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        VOWELS = \"aeiouAEIOU\"\n",
    "        a, b = s[:len(s) // 2], s[len(s) // 2:]\n",
    "        return sum(c in VOWELS for c in a) == sum(c in VOWELS for c in b)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from re import findall\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        return len(re.findall(r'[aeiou]',s[:len(s)//2],re.I))==len(re.findall(r'[aeiou]',s[len(s)//2:],re.I))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        nums = ['a','e','i','o','u','A','E','I','O','U']\n",
    "        cnt = 0\n",
    "        left = 0\n",
    "        right = len(s)-1\n",
    "        while left < right:\n",
    "            if s[left] in nums:\n",
    "                cnt += 1\n",
    "            if s[right] in nums:\n",
    "                cnt -= 1\n",
    "            left += 1\n",
    "            right -= 1\n",
    "        return cnt == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        a = b = 0\n",
    "        for i in s[:len(s)//2]:\n",
    "            if i in ['a', 'e','i','o','u','A','E','I','O','U']:\n",
    "                a += 1\n",
    "        for j in s[len(s)//2:]:\n",
    "            if j in ['a','e','i','o','u','A','E','I','O','U']:\n",
    "                b += 1      \n",
    "        return a == b\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def halvesAreAlike(self, s: str) -> bool:\n",
    "        return(\n",
    "            sum([ 1 for _ in s[0:len(s)//2] if _ in ('a','e','i','o','u','A','E','I','O','U')]) == \n",
    "            sum([ 1 for _ in s[len(s)//2:] if _ in ('a','e','i','o','u','A','E','I','O','U')])\n",
    "            )\n",
    "        "
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
